﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace WmsApp.Window.Editor
{
    public partial class FormInputId : DevExpress.XtraEditors.XtraForm
    {
        public delegate bool ValidateInputIdEventHandler(string value,out string msg);

        public event ValidateInputIdEventHandler ValidateInputId = null;

        public FormInputId()
        {
            InitializeComponent();
        }

        public string Label
        {
            get { return this.labelText.Text; }
            set { this.labelText.Text = value; }
        }

        public virtual string InputId
        {
            get{ return "L"+ this.textEditID.Text.Trim();}
        }

        private void CmdOkClick(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textEditID.Text.Trim()) || textEditID.Text.Trim().Length<6)
            {
                this.textEditID.Focus();
                return;
            }

            if(ValidateInputId != null)
            {
                string msg;
                bool result = ValidateInputId(InputId, out msg);
                if(result)
                {
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
                else
                {
                    XtraMessageBox.Show(msg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }

        private void CmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}